package com.fish.start.animation.views;


import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.Gravity;

import com.fish.start.animation.AnimationSet;
import com.fish.start.animation.R;
import com.fish.start.animation.StartAnimationActivity;
import com.fish.start.animation.Attr.AbstractWay;
import com.fish.start.animation.Attr.BitmapWay;

public class StartBackGroundView extends FishView  {
	
	private static final String tag = StartBackGroundView.class.getSimpleName();
	public static final int START_BG_VIEW_DRAW_STOP = 200;
	public static final int START_BG__VIEW_DRAW_DESTORY = 201;

	private static final String backColor = "#000080";
 	private static final int DRAW_SPAN = 100;
	private StartAnimationActivity mStartAnimationActivity;
	private AbstractWay mAnimationAttr;
	public StartBackGroundView(Context aStartAnimationActivity) {
		super(aStartAnimationActivity);
		getHolder().addCallback(this);
 		mStartAnimationActivity = (StartAnimationActivity)aStartAnimationActivity;
		setCanvasDrawInterface(this);
		setAnimatonCallBack(this);
		setHandler(mStartAnimationActivity.mHahdler);
	}
	public StartBackGroundView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		getHolder().addCallback(this);
 		mStartAnimationActivity = (StartAnimationActivity)context;
		setCanvasDrawInterface(this);
		setAnimatonCallBack(this);
		setHandler(mStartAnimationActivity.mHahdler);
	}
	@Override
	public void draw(Canvas aCanvas){
		super.draw(aCanvas);
		mAnimationAttr = mAnimationSet.pop();
		drawCanvas(aCanvas ,mAnimationAttr);
	}
	
	@Override
	public void drawSelf(Canvas aCanvas) {
		try{
			super.drawSelf(aCanvas);
		}catch(Exception e){
			handlerException(e);
		}
	} 
	@Override
	public void produceAnimation(AnimationSet mAnimations) {
		try{
			super.produceAnimation(mAnimations);
			AbstractWay aw = new BitmapWay(this,
					BitmapFactory.decodeStream(getResources().openRawResource(R.raw.light), null, getOpt()));
			aw.setLayoutGravity(Gravity.CENTER);
			aw.createAnimatons(mAnimations);
		}catch(Exception e){
			handlerException(e);
		}
	}
	
	@Override
	public void onStop() {
		handler(START_BG_VIEW_DRAW_STOP,null);
	}
	@Override
	public void onDestory() {
		super.onDestory();
		handler(START_BG__VIEW_DRAW_DESTORY,null);		
	}
}
